package com.google.code.opencode.dao;

import java.util.Date;
import java.util.List;

import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import com.google.code.opencode.model.Feed;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
public class FeedDaoIT {

	@Autowired
	private FeedDao feedDao;

	@Test
	@Transactional
	public void testLookup() {
		List<Feed> feeds = feedDao.lookup();
		assertNotNull(feeds);
	}

	@Test
	@Transactional
	public void testLookup_ById() {
		Integer id = 1;
		Feed feed = feedDao.lookup(id);
		assertNotNull(feed);
	}

	@Test
	@Transactional
	public void testUpdate() {
		Integer id = 1;
		Feed feed = feedDao.lookup(id);

		String testUrl = "http://www.consultek.us";

		feed.setUrl(testUrl);
		feed = feedDao.update(feed);

		feed = feedDao.lookup(id);
		assertEquals(feed.getUrl(), testUrl);
	}

	@Test
	@Transactional
	public void testCreate() {
		Feed feed = new Feed();
		feed.setName("name");
		feed.setLastPublishedDate(new Date());
		feed.setUrl("http://www.consultek.us");
		feed = feedDao.create(feed);
		assertNotNull(feed.getId());
	}

}
